/* eslint-disable no-undef */
import dayjs from 'dayjs';
// 检验编码
export const getCheckCoding = (arr, internalCode) => {
	const len = arr.length;
	console.log(arr, 'arr');
	const date = dayjs().format('YYYYMMDD');
	return `${date}${internalCode}-${len + 1}`;
};

// 检验编码检查
export const codeVerificationCheck = (tableData, data) => {
	if (!tableData?.find((item) => data.insCode === item.insCode)) {
		return Promise.resolve();
	}
	uni.showToast({
		title: '检验编码重复！',
		icon: 'error',
	});
	return Promise.reject('检验编码不能重复！');
};

export const formatSelectList = (list, map) => {
	return list.map((item) => {
		if (typeof item === 'string') {
			return {
				text: item,
				value: item,
			};
		}
		return {
			...item,
			text: typeof map === 'string' ? item[map] : item[map.text],
			value: typeof map === 'string' ? item[map] : item[map.value],
		};
	});
};

export const getTwoLayersMenuList = (data) => {
	const result = [];
	if (Array.isArray(data)) {
		data.forEach((item) => {
			if (item.children) {
				item.children.forEach((item2) => {
					result.push(item2);
				});
			}
		});
		return result;
	}
	return data;
};
